<template>
  <div class="home-catelist">
    <h2>电台分类</h2>
    <div class="wrapper" >
      <ul class="content" >
        <li
          v-for="(item, index) in listData"
          :key="index"
        >
          <!-- v-for 类似增强for循环。item为声明的对象，index即当前项的索引，Key是主要为了标识。 index和key是可选的
          listdata为需要遍历的数组。@click=""为单击事件-->
          <div class="avatarUrl">
            <van-image :src="item.picUWPUrl" radius="1rem" />
          </div>
          <span>{{ item.name }}</span>
        </li>
      </ul>
    </div>
  </div>
</template>
<script>
import { betterScrollHorizontal } from "../../common/betterScroll.js";
export default {
  data() {
    return {
      listData: [],
    };
  },
  created() {
    this.getListData();
  },

  methods: {
    //获取到推荐歌单的数据
    getListData() {
      this.$request("get", "/dj/catelist").then((res) => {
        console.log(res.categories);
        this.listData=res.categories;
        if (res.result == 100) {
          this.listData = res.categories;
        }
        betterScrollHorizontal(
          this,
          this.$refs.wrapper,
          this.$refs.content,
          this.listData.lenght,
          10
        );
      });
    },
  },
};
</script>
<style scoped>
h2{
  text-align: left;
}
.avatarUrl {
  position: relative;
  
}
.wrapper {
  width: 100%;
  overflow: hidden;
}
ul.content {
  width: calc(12 * 6rem);
  
}
ul.content li {
  display: inline-block;
  width: 8rem;
  vertical-align: top;
}
ul.content li * {
  margin: 0.1rem;
}
ul.content li > span {
  font-size: 0.8rem;
  color: #54493b;
}
</style>